﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using VonaJobs.DAL.DAO;

namespace VonaJobs.DAL.Gatway
{
    public class SeekerUserGateway:DBGateway
    {
        public string SaveNewSeekerUser(SeekerUser seekerUser)
        {
            try
            {
                ConnectionObj.Open();
                CommandObj.CommandText =
                    string.Format("insert into tblSeekerUser values(@Name,@Email,@Password,@Country,@Location)");
                CommandObj.Parameters.Clear();
                CommandObj.Parameters.Add("@Name", SqlDbType.Int).Value = seekerUser.Name;
                CommandObj.Parameters.Add("@Email", SqlDbType.NVarChar).Value = seekerUser.Email;
                CommandObj.Parameters.Add("@Password", SqlDbType.DateTime).Value = seekerUser.Password;
                CommandObj.Parameters.Add("@Country", SqlDbType.NVarChar).Value = seekerUser.Country;
                CommandObj.Parameters.Add("@Location", SqlDbType.NVarChar).Value = seekerUser.Location;
                CommandObj.ExecuteNonQuery();
                return "New seeker user created successfully";
            }
            catch (Exception)
            {
                throw new Exception("Message Not Send, Server Error !");
            }
            finally
            {
                if (ConnectionObj != null && ConnectionObj.State == ConnectionState.Open)
                {
                    ConnectionObj.Close();
                }

            }
        }

        public string SendEmailToJobCompany(Seeker seeker,Employer employer)
        {
            try
            {
                ConnectionObj.Open();
                CommandObj.CommandText = string.Format("insert into tblEmailToCompany values(@SeekerId,@SeekerEmail,@CompanyEmail,@CoverLetter,@Resume)");
                CommandObj.Parameters.Clear();
                CommandObj.Parameters.Add("@SeekerId", SqlDbType.Int).Value = seeker.Id;
                CommandObj.Parameters.Add("@SeekerEmail", SqlDbType.NVarChar).Value = seeker.SeekerUser.Email;
                CommandObj.Parameters.Add("@CompanyEmail", SqlDbType.NVarChar).Value = employer.EmployerUser.Email;
                CommandObj.Parameters.Add("@CoverLetter", SqlDbType.NVarChar).Value = seeker.CoverLetter;
                CommandObj.Parameters.Add("@Resume", SqlDbType.NVarChar).Value = seeker.Resume;
            }
            catch (Exception)
            {
                
                throw;
            }
            return "Create";
        }

        
    }
}